package com.android.Lmaps;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.app.Activity;
import android.content.Intent;

public class MarkerClick extends Activity {

	Button btnComeHere, btnEdit,btnRemove,btnShareOrNot,btndate;
	
	TextView lblContact,lblAddress,lblPrice;
	
	ImageView imgShare;
	
	//___________________________________________________________________
	Intent mainInten;
	Bundle mydata;
	Boolean flagEdit =false;
	//___________________________________________________________________
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_marker_click);
		//___________________________________________________________________
		btnComeHere=(Button)findViewById(R.id.button_marker_comhere);
		btnEdit=(Button)findViewById(R.id.button_marker_Edit);
		btnRemove=(Button)findViewById(R.id.button_marker_remove);
		btnShareOrNot=(Button)findViewById(R.id.button_marker_share);
		btndate=(Button)findViewById(R.id.button_marker_up);
		
		lblContact=(TextView)findViewById(R.id.textView_marker_contact);
		lblAddress=(TextView)findViewById(R.id.textView_marker_address);
		lblPrice=(TextView)findViewById(R.id.textView_marker_price);
		
		imgShare=(ImageView)findViewById(R.id.imageView_marker_share);
		//___________________________________________________________________
		mainInten = getIntent();
		mydata = mainInten.getExtras();
		
		lblAddress.setText("Address: "+mydata.getString("address"));
		
		lblContact.setText("Contact: "+mydata.getString("contact"));
		
		Double pric = mydata.getDouble("price");
		if(pric<=-1.0)
		{
			lblPrice.setText("Price: agreement");
		}
		else
		{
			lblPrice.setText("Price: "+pric.toString());
		}
		
		flagEdit=mydata.getBoolean("personshare");
		
		if(flagEdit)
		{
			imgShare.setBackgroundResource(R.drawable.checkbox_true);
		}
		else
		{
			imgShare.setBackgroundResource(R.drawable.checkbox_unchecked);
		}
		//___________________________________________________________________
		btnComeHere.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				mydata.putInt("type", 0);//come here
				mainInten.putExtras(mydata);
				setResult(Activity.RESULT_OK, mainInten);
				finish();
			}
		});
		btnEdit.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				//call edit
				Log.d("Edit	_", "1");
				Intent editEntent = new Intent(MarkerClick.this,AddNewLocation.class);
				Log.d("Edit	_", "2");
				mydata.putBoolean("stype", false);
				Log.d("Edit	_", "3");
				editEntent.putExtras(mydata);
				Log.d("Edit	_", "4");
				startActivityForResult(editEntent,999);
				Log.d("Edit	_", "5");
			}
		});
		btnRemove.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				mydata.putInt("type", 1);//remove
				mainInten.putExtras(mydata);
				setResult(Activity.RESULT_OK, mainInten);
				finish();
			}
		});
		btnShareOrNot.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if(flagEdit)
				{
					mydata.putBoolean("personshare", false);
				}
				else
				{
					mydata.putBoolean("personshare", true);
				}
				
				mydata.putInt("type", 2);//edit
				mainInten.putExtras(mydata);
				setResult(Activity.RESULT_OK, mainInten);
				finish();
			}
		});
		btndate.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				mydata.putInt("type", 2);//edit
				mainInten.putExtras(mydata);
				setResult(Activity.RESULT_OK, mainInten);
				finish();
			}
		});
		//___________________________________________________________________
	}
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		switch (requestCode) {
		case 999:
			mydata.putInt("type", 2);//edit
			mydata = data.getExtras();
			mainInten.putExtras(mydata);
			setResult(resultCode, mainInten);
			finish();
			break;

		default:
			break;
		}
	}

}
